package org.example.springkafka.POJO;

import com.alibaba.fastjson.JSON;
import org.apache.kafka.common.serialization.Deserializer;

import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;

public class UserDeserializer implements Deserializer<User> {
    @Override
    public User deserialize(String topic, byte[] data) {
//        return JSON.parseObject(data, User.class);
        ByteBuffer buffer = ByteBuffer.allocate(data.length);
        buffer.put(data);
        buffer.flip();
        Long id = buffer.getLong();
        int nameLength = buffer.getInt();
        String name = new String(buffer.get(data,12,nameLength).array(), StandardCharsets.UTF_8 ).trim();
        int sex = buffer.getInt();
        return new User(id,name,sex);
    }
}
